package com.tourism.controller;

import com.github.pagehelper.PageInfo;
import com.tourism.entity.Line;
import com.tourism.entity.LineQuery;
import com.tourism.exception.GlobalException;
import com.tourism.service.LineService;
import com.tourism.util.common.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 线路相关的控制器
 * @Author z
 * @Date 2021-03-01 20:40
 */
@Controller
@RequestMapping("/line")
public class LineController {


    @Autowired
    private LineService lineService;

    /**
     * 根据线路id查询线路信息
     *
     * @param id
     * @return
     */
    @GetMapping("/getLineById")
    @ResponseBody
    public Line getLineById(Long id) {
        return lineService.getLineById(id);
    }


    /**
     * 新增线路
     *
     * @param line
     * @return
     */
    @PostMapping("/addLine")
    @ResponseBody
    public Response addLine(@RequestBody Line line) throws GlobalException {
        return Response.success(lineService.addLine(line));

    }
    /**
     * 修改线路
     *
     * @param line
     * @return
     */
    @PostMapping("/updateLine")
    @ResponseBody
    public Response updateLine(@RequestBody Line line) {
        return Response.success(lineService.updateLine(line));

    }

    /**
     * 删除线路
     *
     * @param id
     * @return
     */
//    @GetMapping("/deleteLineById")
//    @ResponseBody
//    public Response deleteLineById(Long id) {
//        return Response.success(lineService.deleteLineById(id));
//
//    }
    @DeleteMapping("/deleteLineById")
    @ResponseBody
    public Response deleteLineById(Long id) {
        return Response.success(lineService.deleteLineById(id));

    }

    /**
     * 判断线路是否存在
     *
     * @param name
     * @param id
     * @return
     */
    @PostMapping("/existLine")
    @ResponseBody
    public boolean existLine(String name, String id) {
        return lineService.existLine(name, id);
    }

    /**
     * 查询线路列表
     *
     * @param lineQuery
     * @return
     */
    @PostMapping("/getLineList")
    @ResponseBody
    public PageInfo<Line> getLineList(@RequestBody LineQuery lineQuery) {
        return lineService.getLineList(lineQuery);
    }

}
